﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeiXinPF.Common;

namespace WeiXinPF.Web.weixin.vote
{
    public partial class list : WeiXinPage
    {
        protected string yuming = string.Empty;
        protected int wid = 0;
        protected int totalCount;
        protected int page;
        protected int pageSize;
        BLL.wx_vote_base gbll = new BLL.wx_vote_base();

        protected void Page_Load(object sender, EventArgs e)
        {
            yuming = MyCommFun.getWebSite();
            wid = MyCommFun.RequestInt("wid");
            this.pageSize = GetPageSize(10); //每页数量
            if (!Page.IsPostBack)
            {
                yuming = MyCommFun.getWebSite();
                RptBind(wid, "", "id desc");
            }
        }

        private void RptBind(int wid, string _strWhere, string _orderby)
        {
            //判断是否已经设置了微留言基本信息
            _strWhere = "wId=" + wid + " " + _strWhere;

            this.page = MXRequest.GetQueryInt("page", 1);

            DataSet ds = gbll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
            // DataSet ds = gbll.GetList( _strWhere);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr;

                int count = ds.Tables[0].Rows.Count;
                for (int i = 0; i < count; i++)
                {
                    dr = ds.Tables[0].Rows[i];
                }
                ds.AcceptChanges();
            }
            this.rptList.DataSource = ds;
            this.rptList.DataBind();

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("list.aspx", "typeid={0}&page={2}", "__id__");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    Utils.WriteCookie("vote_list_page_size", _pagesize.ToString(), 14400);
                }
            }
            Response.Redirect(Utils.CombUrlTxt("list.aspx", ""));
        }

        private int GetPageSize(int _default_size)
        {
            int _pagesize;
            if (int.TryParse(Utils.GetCookie("vote_list_page_size"), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    return _pagesize;
                }
            }
            return _default_size;
        }
    }
}